﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.AspNet.SignalR;
using models;

namespace MvcApplication3.Hubs
{
    public class Game : Hub
    {
        public static FoulekModelContainer context;
        public string Name;
        public Game()
        {
            if (context == null)
            {
                context = new FoulekModelContainer();
            }
        }

        public void Join(int gameSessionID)
        {
            //var gameSession = context.GameSessions.Find(gameSessionID);

            //var user = context.Users.Where(u => u.Email == Context.User.Identity.Name).Single();

            //user.UserSessions.Add(new UserGameSession()
            //{
            //    Session = gameSession,
            //    JoinedDate = DateTime.Now
            //});

            //Groups.Add(Context.ConnectionId, gameSession.Name);

        }

        public void Send(string message)
        {
            Clients.All.send(message);
        }

        public dynamic GetGame()
        {
            //var userSession = context.UserGameSessions.First(u => u.User.Email.Contains("yoann"));
            //var randomQuestion = userSession.Session.Game.GameEngine.Questions.AsQueryable().OrderBy(x => Guid.NewGuid()).Where(u => u.Language == userSession.User.Language).Take(1).Single();
            //context.Questions.Find(randomQuestion.Id, userSession.User.LanguageId);
            //string sql = randomQuestion.ToString();
         
            //return new { Text = randomQuestion.Text, ID = 7 };
            return 0;
        }
    }
}